package com.nyist.springcloud.controller;

import com.nyist.springcloud.ResultVO;
import com.nyist.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author yangxiaogen
 * @date 2021/1/23 17:02
 */
@RestController
@RequestMapping("/consumer")
@Slf4j
public class OrderController {

    //public static final String PAYMENT_URL = "http://127.0.0.1:8001";
    public static final String PAYMENT_URL = "http://PAYMENT-SERVICE";

    @Autowired
    private RestTemplate restTemplate;

    @PostMapping("/pay/create")
    public ResultVO<Payment> createPay(@RequestBody Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL+"/pay/create",payment,ResultVO.class);
    }

    @PostMapping("/pay/get")
    public ResultVO<Payment> getPay(@RequestBody Payment payment) {
        ResultVO<Payment> resultVO = restTemplate.postForObject(PAYMENT_URL + "/pay/get", payment, ResultVO.class);
        return resultVO;
    }

    /*@GetMapping("/get/{id}")
    public ResultVO<Payment> getPay(@PathVariable("id") String id) {
        return restTemplate.getForObject(PAYMENT_URL+"/pay/get"+id,ResultVO.class);
    }*/

}
